#include "frmcourse.h"
#include "ui_frmcourse.h"
#include "qcustomcalendarwidget.h"
#include "courseitemwidget.h"
#include "quihelper.h"

FrmCourse::FrmCourse(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::FrmCourse)
{
    ui->setupUi(this);

    QCustomCalendarWidget * calendarWidget = new QCustomCalendarWidget(this);
    ui->dtEStart->setCalendarPopup(true);  // 日历弹出
    ui->dtEStart->setCalendarWidget(calendarWidget);
    ui->dtEStart->setMinimumDate(QDate::currentDate().addDays(0));  // 0天
    ui->dtEStart->setMaximumDate(QDate::currentDate().addDays(365));  // +365天
    ui->dtEStart->setContextMenuPolicy(Qt::NoContextMenu);
    ui->dtEStart->setFixedSize(100, 26);
    ui->dtEStart->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    ui->dtEEnd->setCalendarPopup(true);  // 日历弹出
    ui->dtEEnd->setCalendarWidget(calendarWidget);
    ui->dtEEnd->setMinimumDate(QDate::currentDate().addDays(0));  // 0天
    ui->dtEEnd->setMaximumDate(QDate::currentDate().addDays(365));  // +365天
    ui->dtEEnd->setContextMenuPolicy(Qt::NoContextMenu);
    ui->dtEEnd->setFixedSize(100, 26);
    ui->dtEEnd->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

    calendarWidget->disconnect(SIGNAL(selectionChanged()));
    calendarWidget->disconnect(SIGNAL(clicked(QDate)));

    //connect(calendarWidget,SIGNAL(signalSetCalendarTime(QDate)),this,SLOT(dtSetDate(QDate&)));
    initForm();
}

FrmCourse::~FrmCourse()
{
    delete ui;
}

void FrmCourse::initForm()
{
    initMenu();

    CourseItemWidget *crsitem=new CourseItemWidget(ui->widgetContent);
    crsitem->setGeometry(10,0,this->width()-20,100);
}

void FrmCourse::initMenu()
{
    mainMenuBar=new QMenuBar(ui->widgetMenu);

    QMenu *actcrstset=mainMenuBar->addMenu("课程设置");
    QAction *actsubjects=new QAction("学科科目",this);
    QAction *acttechcrs=new QAction("学科开班",this);
    actcrstset->addAction(actsubjects);
    actcrstset->addAction(acttechcrs);

    QMenu *actinfo=mainMenuBar->addMenu("信息录入");
    QAction *actinfotech=new QAction("教师信息",this);
    QAction *actinfostu=new QAction("学生信息",this);
    actinfo->addAction(actinfotech);
    actinfo->addAction(actinfostu);


    connect(actsubjects,SIGNAL(triggered(bool)),this,SLOT(showSubjects()));
    connect(acttechcrs,SIGNAL(triggered(bool)),this,SLOT(showTechCrst()));
    connect(actinfotech,SIGNAL(triggered()),this,SLOT(showTeachInfo()));
    connect(actinfostu,SIGNAL(triggered()),this,SLOT(showStuInfo()));
}

void FrmCourse::showSubjects()
{
    FrmSubjects *frm=new FrmSubjects;
    frm->setWindowModality(Qt::WindowModal);
    frm->setWindowFlags(Qt::WindowCloseButtonHint);
    frm->setWindowTitle(tr("学科科目"));
    frm->show();
}

void FrmCourse::showTechCrst()
{
    FrmTechCrst * frm=new FrmTechCrst;
    frm->setWindowModality(Qt::WindowModal);
    frm->setWindowFlags(Qt::WindowCloseButtonHint);
    frm->setWindowTitle(tr("学科开班"));
    frm->show();
}

void FrmCourse::showTeachInfo()
{
    FrmTecherlst *frm=new FrmTecherlst;
    frm->setWindowModality(Qt::WindowModal);
    frm->setWindowFlags(Qt::WindowCloseButtonHint);
    frm->setWindowTitle(tr("教师信息"));
    frm->show();
}

void FrmCourse::showStuInfo()
{
    FrmStudlst *frm=new FrmStudlst;
    frm->setWindowModality(Qt::WindowModal);
    frm->setWindowFlags(Qt::WindowCloseButtonHint);
    frm->setWindowTitle(tr("学生信息"));
    frm->show();
}

void FrmCourse::on_btnQuery_clicked()
{

}

void FrmCourse::on_btnModify_clicked()
{
    FrmCourseDay *frm=new FrmCourseDay;
    frm->setWindowModality(Qt::WindowModal);
    frm->setWindowFlags(Qt::WindowCloseButtonHint);
    frm->setWindowTitle(tr("修改排课时间"));
    frm->show();
}

